package com.dong.system.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;


@AllArgsConstructor
public enum MenuTypeEnum {

    CATALOG("0", "目录"),
    MENU("1", "菜单"),
    BUTTON("2", "按钮"),
    ;

    @Getter
    private final String code;

    @Getter
    private final String name;

    public static MenuTypeEnum queryName(String code) {
        return Arrays.stream(MenuTypeEnum.values()).filter(m -> Objects.equals(code, m.getCode())).findFirst().orElse(null);
    }
    /**
     * 根据code 查name
     * @param code
     * @return
     */
    public static String getMenuTypeName(String code) {
        return Optional.ofNullable(MenuTypeEnum.queryName(code)).map(MenuTypeEnum::getName).orElse(null);
    }
}
